/*

Dofile: figures_3_4_appendix.do 

Date: Dec. 10, 2016 
Aim: Non-linear effect of the tax rate  for different samples

Input: base_for_reg.dta 
Auxilary dofile: figure.do
Output: 7 .eps files  figure`sample'.eps
Reported in the online appendix: 
- "Figure A.3 – Threshold effect of corporate tax rate on transfer pricing"
- "Figure A.4 – Threshold effect of corporate tax rate on transfer pricing"

*/ 

cd $datapath
use base_for_reg, clear 

drop cty_*
qui tab pays, g(cty_) 

global control inter_linvemtr inter_ldist inter_tarif inter_lgdpc cty_*
xtreg luv type  $control $condition, fe i(fpt) cluster(pays) nonest
keep if e(sample) 
egen test=group(iso3) 
sum test

preserve 
egen group=group(iso3 emtr)
duplicates drop  group , force 
xtile q_emtr=emtr, n(10) 
bys q_emtr: tab iso3 
keep iso3 q_emtr
sort iso3 
save q_emtr, replace 

restore
sort iso3 
merge m:1 iso3 using q_emtr 
drop _m 

qui tab q_emtr, g(q_)

forvalue i = 1(1)10{
g inter_`i'=type*q_`i'
}

egen memtr=mean(emtr) , by(q_emtr)

save tempi, replace 

cd $dopath
global condition if ((type==1 & tot>p75) | type==0)
global lab large
do figure 

cd $dopath
global condition if ((type==1 & tot<p75) | type==0)
global lab small
do figure 

cd $dopath
global condition if natact!="4"
global lab french
do figure 

cd $dopath
global condition if natact!="1"
global lab foreign
do figure 

cd $dopath
global condition if w==1
global lab homog
do figure 

cd $dopath
global condition if n==1 
global lab diff
do figure 

cd $dopath
global condition if ape<36
global lab no_wholesale
do figure 
